import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractEnglishWord {
    public static void main(String[] args) {
        String pattern = "(?<englishword>[a-z =-].+[a-z])";
        Pattern r = Pattern.compile(pattern);
        Matcher m;
        // 创建 Pattern 对象

        String filePath = "C:\\Users\\sean\\Documents\\englishword\\src\\main\\resources\\source.txt";
        String outFilePath = "C:\\Users\\sean\\Documents\\englishword\\src\\main\\resources\\out.txt";
        try {
            FileReader reader = new FileReader(new File(filePath));
            BufferedReader bufferedReader = new BufferedReader(reader);

            BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outFilePath)));
            String line;
            int lineNum = 0;
            while ((line = bufferedReader.readLine()) != null) {
                m = r.matcher(line);
                lineNum++;
                if (m.find()) {
                    System.out.println("Line:" + lineNum + " value:" + m.group("englishword"));
                    writer.write(m.group("englishword") + "\r\n");

                }
            }
            writer.close();
            bufferedReader.close();
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
